# 导入py2neo库中的Graph、Node、Relationship和Subgraph类
from py2neo import Graph, Node, Relationship, Subgraph

# 连接到本地的Neo4j数据库，指定地址和认证信息
graph = Graph("bolt://localhost:7687", auth=("neo4j", "12345678"))

# 创建一个标签为Person，name为Tom的节点
node1 = Node("Person", name="Tom")
# 创建一个标签为Person，name为Jerry的节点
node2 = Node("Person", name="Jerry")
# 创建一个从Tom指向Jerry的KNOWS关系
rel = Relationship(node1, "KNOWS", node2)

# 构建一个包含上述两个节点和关系的子图
subgraph = Subgraph([node1, node2], [rel])
# 将子图写入到数据库中
graph.create(subgraph)
